package org.lm.cloud.lmcode.model.enums;

import cn.hutool.core.util.ObjUtil;
import lombok.Getter;

@Getter
public enum UserRoleEnum {

    USER("用户", "user"),
    ADMIN("管理员", "admin");

    private final String desc;

    private final String code;

    UserRoleEnum(String desc, String code) {
        this.desc = desc;
        this.code = code;
    }

    /**
     * 根据 value 获取枚举
     *
     * @param code 枚举值的value
     * @return 枚举值
     */
    public static UserRoleEnum getEnumByCode(String code) {
        if (ObjUtil.isEmpty(code)) {
            return null;
        }
        for (UserRoleEnum anEnum : UserRoleEnum.values()) {
            if (anEnum.code.equals(code)) {
                return anEnum;
            }
        }
        return null;
    }
}
